
import request from '../../../utils/request'

Page({
    data:{
        inviData:{},  //邀请函数据
        shopData:{},   //商家数据,
        orderData:{},    //订单数据
        order_id: 0
    },
    onLoad(e) {
        wx.showShareMenu({
            withShareTicket: true
        })

        let id = e.order_id
        this.setData({
            order_id: e.order_id
        })

        request.HttpRequst(true,'showinvitation',false,'',{'order_id':id},"POST",false,res => {
            console.log(res)
            if(res.code == 200){
                this.setData({
                    inviData: res.data.invitation,
                    shopData: res.data.Shop,
                    orderData: res.data.OrderReserve
                })
                this.mapCtx = wx.createMapContext('myMap');
                this.mapCtx.includePoints({
                    padding: [10],
                    points: [{
                        latitude: wx.getStorageSync('latitude'),
                        longitude: wx.getStorageSync('longitude')
                    }]
                })
            }else{
                wx.showModal({
                    title: '提示',
                    content: res.info,
                    showCancel: false
                })
            }
        })
    },
    onReady() {
        wx.setNavigationBarTitle({
            title: '邀请函'
        })
    },
    backIndex() {
        wx.switchTab({
            url:'../../../pages/index/index'
        })
    },

    //分享
    onShareAppMessage: function (res) {
        if (res.from === 'button') {
          // 来自页面内转发按钮
          console.log(res.target)
        }
        return {
            title: '您收到一份邀请函',
            path: '/pagesA/invitation/commonModel/commonModel?order_id='+this.data.order_id,
            success: function(res) {
                console.log(res)
                wx.showModal({
                    title: '提示',
                    content: '转发成功',
                    showCancel: false
                })
                // 转发成功
            },
            fail: function(res) {
                wx.showModal({
                    title: '提示',
                    content: '转发失败',
                    showCancel: false
                })
                // 转发失败
            }
        }
    },
    callPhone() {
        wx.makePhoneCall({
            phoneNumber: this.data.shopData.shop_phone //拨打电话
        })
    },
    seeLocation(){
        let latitude = Number(this.data.shopData.latitude)
        let longitude = Number(this.data.shopData.longitude)
        wx.openLocation({
            latitude,
            longitude,
            scale: 28
        })
    }
})